home *** CD-ROM | disk | FTP | other *** search
/ Clickx 23 / Clickx 23.iso / DATA / BLENDE~1.ZIP / blender-2.37a-OSX-10.2-powerpc / plugins / texture / clouds2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2005-06-15  |  4.0 KB  |  178 lines

  1. /**
  2.  * $Id: clouds2.c,v 1.1 2003/01/01 15:06:08 hos Exp $
  3.  *
  4.  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  5.  *
  6.  * This program is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU General Public License
  8.  * as published by the Free Software Foundation; either version 2
  9.  * of the License, or (at your option) any later version. The Blender
  10.  * Foundation also sells licenses for use in proprietary software under
  11.  * the Blender License.  See http://www.blender.org/BL/ for information
  12.  * about this.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software Foundation,
  21.  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  *
  23.  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  24.  * All rights reserved.
  25.  *
  26.  * The Original Code is: all of this file.
  27.  *
  28.  * Contributor(s): none yet.
  29.  *
  30.  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  31.  */
  32.  
  33. #include "math.h"
  34. #include "plugin.h"
  35.  
  36. /* ******************** GLOBAL VARIABLES ***************** */
  37.  
  38. /* Texture name */
  39.  
  40. char name[24]= "Clouds2";
  41.  
  42. /* Subtype names must be less than 15 characters */
  43.  
  44. #define NR_TYPES    3
  45. char stnames[NR_TYPES][16]= {"Intens", "Col", "Bump" };
  46.  
  47. /* Structure for buttons, 
  48.  *  butcode      name           default  min  max  0
  49.  */
  50.  
  51. VarStruct varstr[]= {
  52. {    NUM|FLO,    "Offset",        -0.5,      -20.0, 20.0, ""}, 
  53. {    NUM|INT,    "Depth",        8.0,     1.0, 12.0, ""}, 
  54. {    NUM|FLO,    "Scale",        2.2,     -20.0, 20.0, ""},  
  55. {    NUM|FLO,    "Falloff",        1.0,     -20.0, 20.0, ""}
  56. };
  57.  
  58. /* The cast struct is for input in the main doit function
  59.    Varstr and Cast must have the same variables in the same order, 
  60.    INCLUDING dummy variables for label fields. */ 
  61.  
  62. typedef struct Cast {
  63.     float offset;
  64.     int depth;
  65.     float txtscale;
  66.     float falloff;
  67. } Cast;
  68.  
  69. /* result:
  70.    Intensity, R, G, B, Alpha, nor.x, nor.y, nor.z
  71.  */
  72.  
  73. float result[8];
  74.  
  75. /* cfra: the current frame */
  76.  
  77. float cfra;
  78.  
  79. int plugin_tex_doit(int, Cast*, float*, float*, float*);
  80.  
  81. /* ******************** Fixed functions ***************** */
  82.  
  83. int plugin_tex_getversion(void) 
  84. {    
  85.     return B_PLUGIN_VERSION;
  86. }
  87.  
  88. void plugin_but_changed(int but) 
  89. {
  90. }
  91.  
  92. void plugin_init(void)
  93. {
  94.     
  95. }
  96.  
  97. /* this function should not be changed: */
  98.  
  99. void plugin_getinfo(PluginInfo *info)
  100. {
  101.     info->name= name;
  102.     info->stypes= NR_TYPES;
  103.     info->nvars= sizeof(varstr)/sizeof(VarStruct);
  104.     
  105.     info->snames= stnames[0];
  106.     info->result= result;
  107.     info->cfra= &cfra;
  108.     info->varstr= varstr;
  109.  
  110.     info->init= plugin_init;
  111.     info->tex_doit=  (TexDoit) plugin_tex_doit;
  112.     info->callback= plugin_but_changed;
  113. }
  114.  
  115. /* ********************* the texture ******************** */
  116.  
  117.  
  118. /* return 0: One channel texture
  119.    return 1: RGB texture
  120.    return 2: Normals texture */
  121.  
  122. int plugin_tex_doit(int stype, Cast *cast, float *texvec, float *dxt, float *dyt)
  123. {
  124.     float val = 0.0;
  125.     float a = 1.0;
  126.     float p[3];
  127.     float tv[3];
  128.     int i;
  129.  
  130.     tv[0]=(texvec[0]+1.0)/2.0;
  131.     tv[1]=(texvec[1]+1.0)/2.0;
  132.     tv[2]=(texvec[2]+1.0)/2.0;
  133.  
  134.     p[0] = cast->txtscale * tv[0];
  135.     p[1] = cast->txtscale * tv[1];
  136.     p[2] = cast->txtscale * tv[2];
  137.     
  138.     for (i=0; i<cast->depth; i++) {
  139.         val += a * hnoise(1.0, p[0], p[1], p[2]);
  140.         
  141.         p[0] *= 2.0;
  142.         p[1] *= 2.0;
  143.         p[2] *= 2.0;
  144.         a *= 0.5;
  145.     }
  146.     
  147.     /* always return this value */
  148.     result[0] = CLAMP (val+cast->offset, 0.0, 1.0) * pow (fabs(sqrt(tv[0]*tv[0]+tv[1]*tv[1]+tv[2]*tv[2])), cast->falloff);
  149.     
  150.     if(stype==1) {
  151.         /* color? then return 1;
  152.          * 
  153.          * this is r, g, b, a:
  154.          */
  155.         result[1]= 0.5*result[0];
  156.         result[2]= 1.0-val;
  157.         result[3]= fsqrt(fabs(result[0]));
  158.         result[4]= 1.0;
  159.             
  160.         return 1;
  161.     }
  162.     if(stype==2) {
  163.         /* normal? then return 2
  164.          * 
  165.          * This value is the displacement of the actual normal in 
  166.          * the Material calculation. 
  167.          */
  168.         result[5]+= val;
  169.         result[6]+= 1.0-val;
  170.         result[7]= 0.0;
  171.         
  172.         return 2;
  173.     }
  174.     
  175.     return 0;
  176. }
  177.     
  178.